/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.utils {
	import flash.display.Shape;
	
	public class Curtain extends Object {
		private var _rate:Number = .1;
		private var _shape:Shape;
		private var _v:Number;
		public function Curtain(width:Number,height:Number)	{
			_shape = new Shape();
			_shape.graphics.beginFill(0x000000,1);
			_shape.graphics.drawRect(0,0,width+1,height+1);
			_shape.graphics.endFill();
		}
		
		public function fadeIn(a:Number = 2):Shape {
			_shape.alpha = a;
			_v = -_rate;
			return _shape;
		}
		
		public function fadeOut():Shape {
			_shape.alpha = 0;
			_v = _rate;
			return _shape;
		}
		
		public function step():Boolean {
			_shape.alpha += _v;
			return _v < 0 ? _shape.alpha > 0 : _shape.alpha < 1;
		}
		
		public function close():void {
			if (_shape.parent != null) {
				_shape.parent.removeChild(_shape);
			}
		}
	}
}